package com.zqxq.lottery.util;

import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.entity.po.order.UserOrderBetBopPO;
import com.zqxq.lottery.entity.vo.order.FollowOrderVO;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author 苦智
 * @date 2018/8/6 10:37
 * @description
 * @ClassName SelfStringUtils
 */
public class SelfStringUtils extends StrUtils{

    /**
    * @Author 苦智
    * @Description 获取list集合中连续出现次数最多的字符
    * @Date 10:43 2018/8/6
    * @Param [l, target]
    * @return java.lang.Integer
    **/
    public static Integer getMaxContinueNum(String str, String target) {
        int num = 0;
        if (StrUtils.isEmpty(str)){
            return num;
        }
        List<String> l = Arrays.asList(str.split(","));
        List<Integer> c = new ArrayList<>(); //存储计数器
        if (l.size()>0) {
            for (String s : l) {
                if (!target.equals(s)) {
                    num = 0;
                    continue;
                }
                num++;
                c.add(num);
            }
            if (c.size()<1)
                c.add(0);
            return Collections.max(c);
        }else {
            return 0;
        }
    }

    /**
     * 按照List中的某个对象属性值(Int、double、bigdecimal类型的属性)进行排序
     * @param list
     */
    public static List sortByAttribute(List list,Integer type){
        Collections.sort(list, new Comparator(){
            @Override
            public int compare(Object o1, Object o2) {
                FollowOrderVO vo1=(FollowOrderVO)o1;
                FollowOrderVO vo2=(FollowOrderVO)o2;
                switch (type){
                    case 1:
                        if(vo1.getFollows() > vo2.getFollows()){
                            return -1;
                        }else if(vo1.getFollows() == vo2.getFollows()){
                            return 0;
                        }else{
                            return 1;
                        }
                    case 2:
                        if(new BigDecimal(vo1.getHitOdds()).compareTo(new BigDecimal(vo2.getHitOdds()))==1){
                            return -1;
                        }else if(new BigDecimal(vo1.getHitOdds()).compareTo(new BigDecimal(vo2.getHitOdds()))==0){
                            return 0;
                        }else{
                            return 1;
                        }
                    case 3:
                        if(new BigDecimal(vo1.getProfitOdds()).compareTo(new BigDecimal(vo2.getProfitOdds()))==1){
                            return -1;
                        }else if(new BigDecimal(vo1.getProfitOdds()).compareTo(new BigDecimal(vo2.getProfitOdds()))==0){
                            return 0;
                        }else{
                            return 1;
                        }
                    default:
                        return 0;
                }
            }
        });
        return list;
    }

    public static List sortByAttribute(List list){
        Collections.sort(list, new Comparator(){
            @Override
            public int compare(Object o1, Object o2) {
                UserOrderBetBopPO vo1=(UserOrderBetBopPO)o1;
                UserOrderBetBopPO vo2=(UserOrderBetBopPO)o2;
                if(vo1.getExpect_bonus().compareTo(vo2.getExpect_bonus())==-1){
                    return -1;
                }else if(vo1.getExpect_bonus().compareTo(vo2.getExpect_bonus())==0){
                    return 0;
                }else{
                    return 1;
                }
            }
        });
        return list;
    }

    public static void main(String[] args) {
        List<FollowOrderVO> followOrderVOS = new ArrayList<>();
        FollowOrderVO followOrderVO = new FollowOrderVO();
        followOrderVO.setHitOdds("1");
        followOrderVOS.add(followOrderVO);
        followOrderVO = new FollowOrderVO();
        followOrderVO.setHitOdds("2");
        followOrderVOS.add(followOrderVO);
        followOrderVO = new FollowOrderVO();
        followOrderVO.setHitOdds("2.3");
        followOrderVOS.add(followOrderVO);
        followOrderVO = new FollowOrderVO();
        followOrderVO.setHitOdds("1.3");
        followOrderVOS.add(followOrderVO);
        List list = sortByAttribute(followOrderVOS, 2);
        System.out.println(list);
    }
}
